package com.nate.tasking.actions;

import java.util.List;

import javax.jdo.PersistenceManager;

import org.apache.log4j.Logger;

import com.nate.tasking.data.PMF;
import com.nate.tasking.domain.User;
import com.opensymphony.xwork2.ActionSupport;

public class ViewUserAction extends ActionSupport{

	private static final long serialVersionUID = 6390974667995625397L;
	private final Logger logger = Logger.getLogger(ViewUserAction.class);
	private List<User> listOfUsers;

	public String execute(){
		logger.debug("View Users Action");
		
		PersistenceManager pm = PMF.get().getPersistenceManager();
    	try {
    		String query = "select from " + User.class.getName();
    	    listOfUsers = (List<User>) pm.newQuery(query).execute();
    	    System.out.println("user list size: " + listOfUsers.size());
            logger.debug("retrieved users");
        } finally {
            pm.close();
        }
		return SUCCESS;
	}
	
	
	public List<User> getListOfUsers() {
		return listOfUsers;
	}

	public void setListOfUsers(List<User> listOfUsers) {
		this.listOfUsers = listOfUsers;
	}
}
